package com.xoa.service.party;

import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.party.EnCaterParameterMapper;
import com.xoa.dao.party.MapOwnerinfoMapper;
import com.xoa.model.common.SysCode;
import com.xoa.model.party.EnCaterParameter;
import com.xoa.model.users.Users;
import com.xoa.util.DateFormat;
import com.xoa.util.ExcelUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.page.PageParams;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 餐饮
 * Created by gsb on 2018/1/5.
 */
@Service
public class EnCaterParameterService {
    @Resource
    private EnCaterParameterMapper enCaterParameterMapper;

    @Resource
    private SysCodeMapper sysCodeMapper;
    @Resource
    private MapOwnerinfoMapper mapOwnerinfoMapper;

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午13:46:51
     * 类介绍  :   新建
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> insertSelective(EnCaterParameter enCaterParameter, HttpServletRequest request, String gridLocation){
        ToJson<EnCaterParameter> json = new ToJson<>();
        try {
            Users user= SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users());
            if(gridLocation!=null){
                enCaterParameter.setS1(gridLocation);
            }
            enCaterParameter.setCreateUser(user.getUserId());
            enCaterParameter.setCreateTime(DateFormat.getDatestr(new Date()));
            enCaterParameterMapper.insertSelective(enCaterParameter);
            json.setMsg("新建成功");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }
    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午13:55:51
     * 类介绍  :   删除
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> deleteByPrimaryKey(Integer cid){
        ToJson<EnCaterParameter> json = new ToJson<>();
        try {
            enCaterParameterMapper.deleteByPrimaryKey(cid);
            json.setMsg("删除成功");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午14:25:51
     * 类介绍  :   修改
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> updateByPrimaryKeySelective(EnCaterParameter enCaterParameter, HttpServletRequest request, String gridLocation){
        ToJson<EnCaterParameter> json = new ToJson<>();
        try {
            if(gridLocation!=null){
                enCaterParameter.setS1(gridLocation);
            }
            enCaterParameterMapper.updateByPrimaryKeySelective(enCaterParameter);
            json.setMsg("修改成功");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }
    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午14:25:51
     * 类介绍  :   详情
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> selectById(Integer cid){
        ToJson<EnCaterParameter> json = new ToJson<>();
        try {
            EnCaterParameter enCaterParameter = enCaterParameterMapper.selectById(cid);
            if (enCaterParameter.getGridId()!=null && enCaterParameter.getGridId()!=""){
                enCaterParameter.setCodeName(sysCodeMapper.getSingleCode("TYPE_OF_ACCOUNT", enCaterParameter.getGridId()).getCodeName());
            }
            json.setObject(enCaterParameter);
            json.setMsg("成功");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }



    public ToJson<EnCaterParameter> queryByList(){
        ToJson<EnCaterParameter> json = new ToJson<>();
        try {

            List<EnCaterParameter> enCaterParameters=enCaterParameterMapper.queryByList();
            if(enCaterParameters.size()>0) {
                json.setMsg("ok");
                json.setObj(enCaterParameters);
                json.setFlag(0);
            }
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }



    public ToJson<EnCaterParameter> selectByList(EnCaterParameter enCaterParameter, Integer page, Integer pageSize,
                                                 boolean useFlag, HttpServletRequest request, HttpServletResponse response){

        ToJson<EnCaterParameter> json = new ToJson<>();
        try {

            PageParams pageParams=new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            if(useFlag){
                map.put("page", pageParams);
            }
            map.put("s1",enCaterParameter.getS1());

            List<EnCaterParameter> enCaterParameterList = enCaterParameterMapper.selectByList(map);
           /* if(enCaterParameterList.size()>0){
                String detailsAddress=mapOwnerinfoMapper.selectByLabelName(enCaterParameter.getS1());
                enCaterParameterList.get(0).setDetailsAddress(detailsAddress);
            }*/
            if(enCaterParameterList!=null&&enCaterParameterList.size()>0){
                for (EnCaterParameter enCaterParameter1:enCaterParameterList){
                    if (enCaterParameter1 != null && !StringUtils.checkNull(enCaterParameter1.getGridId())) {
                        SysCode singleCode = sysCodeMapper.getSingleCode("TYPE_OF_ACCOUNT", enCaterParameter1.getGridId());
                        if (singleCode.getCodeName() != null && !"".equals(singleCode.getCodeName())){
                            enCaterParameter1.setGridId(singleCode.getCodeName());
                        }else {
                            enCaterParameter1.setGridId("");
                        }
                    }
                    if ("1".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("早点");
                    }else if ("2".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("中餐");
                    }else if ("3".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("西餐");
                    }else if ("4".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("烧烤");
                    }else if ("5".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("烤肉");
                    }else if ("6".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("韩餐");
                    }else if ("7".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("火锅");
                    }else if ("8".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("麻辣烫");
                    }else if ("9".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("其他");
                    }else {
                        enCaterParameter1.setDiningType("");
                    }
                    if ("1".equals(enCaterParameter1.getBusinessLicense())){
                        enCaterParameter1.setBusinessLicense("有");
                    }else if("0".equals(enCaterParameter1.getBusinessLicense())){
                        enCaterParameter1.setBusinessLicense("无");
                    }else {
                        enCaterParameter1.setBusinessLicense("");
                    }
                    if ("1".equals(enCaterParameter1.getSanitaryPermit())){
                        enCaterParameter1.setSanitaryPermit("有");
                    }else  if ("0".equals(enCaterParameter1.getSanitaryPermit())){
                        enCaterParameter1.setSanitaryPermit("无");
                    }else {
                        enCaterParameter1.setSanitaryPermit("");
                    }
                    if ("1".equals(enCaterParameter1.getEiaApproval())){
                        enCaterParameter1.setEiaApproval("有");
                    }else  if ("0".equals(enCaterParameter1.getEiaApproval())){
                        enCaterParameter1.setEiaApproval("无");
                    }else {
                        enCaterParameter1.setEiaApproval("");
                    }
                    if ("1".equals(enCaterParameter1.getEiaAccpet())){
                        enCaterParameter1.setEiaAccpet("有");
                    }else if ("0".equals(enCaterParameter1.getEiaAccpet())){
                        enCaterParameter1.setEiaAccpet("无");
                    }else {
                        enCaterParameter1.setEiaAccpet("");
                    }
                    if ("1".equals(enCaterParameter1.getInstallationContract())){
                        enCaterParameter1.setInstallationContract("有");
                    }else if ("0".equals(enCaterParameter1.getInstallationContract())){
                        enCaterParameter1.setInstallationContract("无");
                    }else {
                        enCaterParameter1.setInstallationContract("");
                    }
                    if ("1".equals(enCaterParameter1.getEquipmentReport())){
                        enCaterParameter1.setEquipmentReport("有");
                    }else if ("0".equals(enCaterParameter1.getEquipmentReport())){
                        enCaterParameter1.setEquipmentReport("无");
                    }else {
                        enCaterParameter1.setEquipmentReport("");
                    }
                    if ("1".equals(enCaterParameter1.getOilExitPhoto())){
                        enCaterParameter1.setOilExitPhoto("有");
                    }else if ("0".equals(enCaterParameter1.getOilExitPhoto())){
                        enCaterParameter1.setOilExitPhoto("无");
                    }else {
                        enCaterParameter1.setOilExitPhoto("");
                    }
                    if ("1".equals(enCaterParameter1.getOilFumePurificationEquipment())){
                        enCaterParameter1.setOilFumePurificationEquipment("有");
                    }else  if ("0".equals(enCaterParameter1.getOilFumePurificationEquipment())){
                        enCaterParameter1.setOilFumePurificationEquipment("无");
                    }else {
                        enCaterParameter1.setOilFumePurificationEquipment("");
                    }
                    if ("1".equals(enCaterParameter1.getCleanProtocal())){
                        enCaterParameter1.setCleanProtocal("有");
                    }else if ("0".equals(enCaterParameter1.getCleanProtocal())){
                        enCaterParameter1.setCleanProtocal("无");
                    }else {
                        enCaterParameter1.setCleanProtocal("");
                    }
                    if ("1".equals(enCaterParameter1.getCleanInvoice())){
                        enCaterParameter1.setCleanInvoice("有");
                    }else if ("0".equals(enCaterParameter1.getCleanInvoice())){
                        enCaterParameter1.setCleanInvoice("无");
                    }else {
                        enCaterParameter1.setCleanInvoice("");
                    }
                    if ("1".equals(enCaterParameter1.getUseCarbon())){
                        enCaterParameter1.setUseCarbon("有");
                    }else if ("0".equals(enCaterParameter1.getUseCarbon())){
                        enCaterParameter1.setUseCarbon("无");
                    }else {
                        enCaterParameter1.setUseCarbon("");
                    }
                    if ("1".equals(enCaterParameter1.getMonitorOnline())){
                        enCaterParameter1.setMonitorOnline("有");
                    }else if ("0".equals(enCaterParameter1.getMonitorOnline())){
                        enCaterParameter1.setMonitorOnline("无");
                    }else {
                        enCaterParameter1.setMonitorOnline("");
                    }
                }
            }
            json.setObj(enCaterParameterList);
            json.setFlag(0);
            json.setMsg("ok");

        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午14:25:51
     * 类介绍  :   列表  或 导出 也可条件查询
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> queryList(EnCaterParameter enCaterParameter, Integer page, Integer pageSize,
                                              boolean useFlag, HttpServletRequest request, HttpServletResponse response, String export){

        ToJson<EnCaterParameter> json = new ToJson<>();
        try {
            PageParams pageParams=new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            if(useFlag){
                map.put("page", pageParams);
            }
            List<String> list = new ArrayList<>();

            map.put("enCaterParameter",enCaterParameter);
            if(export==null){
                export="0";
            }
            List<EnCaterParameter> enCaterParameterList = enCaterParameterMapper.queryList(map);
            if(enCaterParameterList!=null&&enCaterParameterList.size()>0){
                for (EnCaterParameter enCaterParameter1:enCaterParameterList){
                    if (enCaterParameter1 != null && !StringUtils.checkNull(enCaterParameter1.getGridId())) {
                        SysCode singleCode = sysCodeMapper.getSingleCode("TYPE_OF_ACCOUNT", enCaterParameter1.getGridId());
                        if (singleCode!=null&& singleCode.getCodeName() != null && !"".equals(singleCode.getCodeName())){
                            enCaterParameter1.setGridId(singleCode.getCodeName());
                        }else {
                            enCaterParameter1.setGridId("");
                        }
                    }
                    if ("1".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("早点");
                    }else if ("2".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("中餐");
                    }else if ("3".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("西餐");
                    }else if ("4".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("烧烤");
                    }else if ("5".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("烤肉");
                    }else if ("6".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("韩餐");
                    }else if ("7".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("火锅");
                    }else if ("8".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("麻辣烫");
                    }else if ("9".equals(enCaterParameter1.getDiningType())){
                        enCaterParameter1.setDiningType("其他");
                    }else {
                        enCaterParameter1.setDiningType("");
                    }
                    if ("1".equals(enCaterParameter1.getBusinessLicense())){
                        enCaterParameter1.setBusinessLicense("有");
                    }else if("0".equals(enCaterParameter1.getBusinessLicense())){
                        enCaterParameter1.setBusinessLicense("无");
                    }else {
                        enCaterParameter1.setBusinessLicense("");
                    }
                    if ("1".equals(enCaterParameter1.getSanitaryPermit())){
                        enCaterParameter1.setSanitaryPermit("有");
                    }else  if ("0".equals(enCaterParameter1.getSanitaryPermit())){
                        enCaterParameter1.setSanitaryPermit("无");
                    }else {
                        enCaterParameter1.setSanitaryPermit("");
                    }
                    if ("1".equals(enCaterParameter1.getEiaApproval())){
                        enCaterParameter1.setEiaApproval("有");
                    }else  if ("0".equals(enCaterParameter1.getEiaApproval())){
                        enCaterParameter1.setEiaApproval("无");
                    }else {
                        enCaterParameter1.setEiaApproval("");
                    }
                    if ("1".equals(enCaterParameter1.getEiaAccpet())){
                        enCaterParameter1.setEiaAccpet("有");
                    }else if ("0".equals(enCaterParameter1.getEiaAccpet())){
                        enCaterParameter1.setEiaAccpet("无");
                    }else {
                        enCaterParameter1.setEiaAccpet("");
                    }
                    if ("1".equals(enCaterParameter1.getInstallationContract())){
                        enCaterParameter1.setInstallationContract("有");
                    }else if ("0".equals(enCaterParameter1.getInstallationContract())){
                        enCaterParameter1.setInstallationContract("无");
                    }else {
                        enCaterParameter1.setInstallationContract("");
                    }
                    if ("1".equals(enCaterParameter1.getEquipmentReport())){
                        enCaterParameter1.setEquipmentReport("有");
                    }else if ("0".equals(enCaterParameter1.getEquipmentReport())){
                        enCaterParameter1.setEquipmentReport("无");
                    }else {
                        enCaterParameter1.setEquipmentReport("");
                    }
                    if ("1".equals(enCaterParameter1.getOilExitPhoto())){
                        enCaterParameter1.setOilExitPhoto("有");
                    }else if ("0".equals(enCaterParameter1.getOilExitPhoto())){
                        enCaterParameter1.setOilExitPhoto("无");
                    }else {
                        enCaterParameter1.setOilExitPhoto("");
                    }
                    if ("1".equals(enCaterParameter1.getOilFumePurificationEquipment())){
                        enCaterParameter1.setOilFumePurificationEquipment("有");
                    }else  if ("0".equals(enCaterParameter1.getOilFumePurificationEquipment())){
                        enCaterParameter1.setOilFumePurificationEquipment("无");
                    }else {
                        enCaterParameter1.setOilFumePurificationEquipment("");
                    }
                    if ("1".equals(enCaterParameter1.getCleanProtocal())){
                        enCaterParameter1.setCleanProtocal("有");
                    }else if ("0".equals(enCaterParameter1.getCleanProtocal())){
                        enCaterParameter1.setCleanProtocal("无");
                    }else {
                        enCaterParameter1.setCleanProtocal("");
                    }
                    if ("1".equals(enCaterParameter1.getCleanInvoice())){
                        enCaterParameter1.setCleanInvoice("有");
                    }else if ("0".equals(enCaterParameter1.getCleanInvoice())){
                        enCaterParameter1.setCleanInvoice("无");
                    }else {
                        enCaterParameter1.setCleanInvoice("");
                    }
                    if ("1".equals(enCaterParameter1.getUseCarbon())){
                        enCaterParameter1.setUseCarbon("有");
                    }else if ("0".equals(enCaterParameter1.getUseCarbon())){
                        enCaterParameter1.setUseCarbon("无");
                    }else {
                        enCaterParameter1.setUseCarbon("");
                    }
                    if ("1".equals(enCaterParameter1.getMonitorOnline())){
                        enCaterParameter1.setMonitorOnline("有");
                    }else if ("0".equals(enCaterParameter1.getMonitorOnline())){
                        enCaterParameter1.setMonitorOnline("无");
                    }else {
                        enCaterParameter1.setMonitorOnline("");
                    }
                }
            }
            json.setObj(enCaterParameterList);
            json.setTotleNum(enCaterParameterMapper.selectCount(enCaterParameter));
            json.setFlag(0);
            json.setMsg("ok");
            if (export.equals("1")){
                HSSFWorkbook workbook1 = ExcelUtil.makeExcelHead("餐饮台账信息", 22);
                String[] secondTitles = {"单位", "单位地址", "所属社区", "联系人", "联系电话","经营面积",
                        "灶头数","餐饮类型","营业执照","卫生许可证","环评批复","环评验收","油烟净化设备安装合同",
                        "设备检测报告", "油烟净化设施与烟道出口照片","油烟净化设备","油烟净化设施清洗协议/资质",
                        "清洗发票或收据","油烟清洗记录","是否使用碳","油烟在线监测","备注"};
                HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbook1, secondTitles);
                String[] beanProperty = {"unit", "unitAddress", "gridId", "cantact", "phoneNumber", "businessArea",
                        "informedNum","diningType","businessLicense","sanitaryPermit","eiaApproval","eiaAccpet",
                        "installationContract","equipmentReport","oilExitPhoto","oilFumePurificationEquipment",
                        "cleanProtocal","cleanInvoice",
                        "cleanRecord","useCarbon","monitorOnline","note"};
                HSSFWorkbook workbook = null;
                workbook = ExcelUtil.exportExcelData(workbook2, enCaterParameterList, beanProperty);
                OutputStream out = response.getOutputStream();
                String filename = "餐饮台账信息记录表.xls";
                filename = FileUtils.encodeDownloadFilename(filename, request.getHeader("user-agent"));
                response.setContentType("application/vnd.ms-excel;charset=UTF-8");
                response.setHeader("content-disposition", "attachment;filename=" + filename);
                workbook.write(out);
                out.close();

            }

        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;
    }

    /**
     *
     * 创建作者:   季佳伟
     * 创建日期:   2018-1-5 下午16:25:51
     * 类介绍  :   导入
     * 构造参数:
     *
     */
    public ToJson<EnCaterParameter> importEnCaterParameter(MultipartFile file, HttpServletResponse response, HttpServletRequest request, HttpSession session) {
        ToJson<EnCaterParameter> json = new ToJson<>();
        Users users= SessionUtils.getSessionInfo(request.getSession(), Users.class,new Users());
        // 成功次数
        Integer successCount = 0;
        try {
              //判读当前系统
                //读取配置文件
                ResourceBundle rb = ResourceBundle.getBundle("upload");
                String osName = System.getProperty("os.name");
                StringBuffer path = new StringBuffer();
                if (osName.toLowerCase().startsWith("win")) {
                    path = path.append(rb.getString("upload.win"));
                } else {
                    path = path.append(rb.getString("upload.linux"));
                }
                // 判断是否为空文件
                if (file.isEmpty()) {
                    json.setMsg("请上传文件！");
                    json.setFlag(1);
                    return json;
            }else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString(), newFileName);
//                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
//                    String readPath = path.append(fileName).toString();
//                    String readPath = file.getInputStream();
                    InputStream in =  file.getInputStream();
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(0);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    List<EnCaterParameter> enCaterParameterList = new ArrayList<EnCaterParameter>();
                    EnCaterParameter enCaterParameter = null;
                    for (int i = 1; i <= lastRowNum; i++) {
                        enCaterParameter = new EnCaterParameter();
                        row = sheetObj.getRow(i);
                        String value = "";
                        if (row != null ) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                if (cell != null ) {
                                    switch (j) {
                                        case 0:
                                            //单位
                                            enCaterParameter.setUnit(cell.getStringCellValue());
                                            break;
                                        case 1:
                                            //单位地址
                                            enCaterParameter.setUnitAddress(cell.getStringCellValue());
                                            break;
                                        case 2:
                                            //所属社区
                                            SysCode sysCode = new SysCode();
                                            sysCode.setCodeName(cell.getStringCellValue().trim());
                                            sysCode.setParentNo("TYPE_OF_ACCOUNT");
                                            SysCode sysCode1 = sysCodeMapper.getCodeNoByNameAndParentNo(sysCode);
                                            if (sysCode1!=null){
                                                enCaterParameter.setGridId(sysCode1.getCodeNo());
                                            }else {
                                                enCaterParameter.setGridId("");
                                            }
                                            break;
                                        case 3:
                                            //联系人
                                            enCaterParameter.setCantact(cell.getStringCellValue());
                                            break;
                                        case 4:
                                            //联系电话
                                            if(cell.getCellType() == CellType.NUMERIC){
                                                cell.setCellType(CellType.STRING);
                                            }
                                            enCaterParameter.setPhoneNumber(cell.getStringCellValue());
                                            break;
                                        case 5:
                                            //经营面积
                                            if(cell.getCellType() == CellType.NUMERIC){
                                                cell.setCellType(CellType.STRING);
                                            }
                                            enCaterParameter.setBusinessArea(cell.getStringCellValue());
                                            break;
                                        case 6:
                                            //灶头数
                                            if(cell.getCellType() == CellType.NUMERIC){
                                                cell.setCellType(CellType.STRING);
                                            }
                                            if(!cell.equals("")){
                                                enCaterParameter.setInformedNum(cell.getStringCellValue());
                                            }
                                            break;
                                        case 7:
                                            //餐饮类型
                                            if ("早点".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("1");
                                            }else if ("中餐".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("2");
                                            }else if ("西餐".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("3");
                                            }else if ("烧烤".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("4");
                                            }else if ("烤肉".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("5");
                                            }else if ("韩餐".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("6");
                                            }else if ("火锅".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("7");
                                            }else if ("麻辣烫".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setDiningType("8");
                                            }else {
                                                enCaterParameter.setDiningType("9");
                                            }
                                            break;
                                        case 8:
                                            //营业执照
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setBusinessLicense("1");
                                            }else {
                                                enCaterParameter.setBusinessLicense("0");
                                            }
                                            break;

                                        case 9:
                                            //卫生许可证
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setSanitaryPermit("1");
                                            }else {
                                                enCaterParameter.setSanitaryPermit("0");
                                            }
                                            break;
                                        case 10:
                                            //环评批复
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setEiaApproval("1");
                                            }else {
                                                enCaterParameter.setEiaApproval("0");
                                            }
                                            break;
                                        case 11:
                                            //环评验收
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setEiaAccpet("1");
                                            }else {
                                                enCaterParameter.setEiaAccpet("0");
                                            }
                                            break;
                                        case 12:
                                            //油烟净化设备安装合同
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setInstallationContract("1");
                                            }else {
                                                enCaterParameter.setInstallationContract("0");
                                            }
                                            break;
                                        case 13:
                                            //设备检测报告
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setEquipmentReport("1");
                                            }else {
                                                enCaterParameter.setEquipmentReport("0");
                                            }
                                            break;
                                        case 14:
                                            //油烟净化设施与烟道出口照片
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setOilExitPhoto("1");
                                            }else {
                                                enCaterParameter.setOilExitPhoto("0");
                                            }
                                            break;
                                        case 15:
                                            //油烟净化设备
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setOilFumePurificationEquipment("1");
                                            }else {
                                                enCaterParameter.setOilFumePurificationEquipment("0");
                                            }
                                            break;
                                        case 16:
                                            //油烟净化设施清洗协议/资质
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setCleanProtocal("1");
                                            }else {
                                                enCaterParameter.setCleanProtocal("0");
                                            }
                                            break;
                                        case 17:
                                            //清洗发票或收据
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setCleanInvoice("1");
                                            }else {
                                                enCaterParameter.setCleanInvoice("0");
                                            }
                                            break;

                                        case 18:
                                            //油烟清洗记录
                                            String result1 = null;
                                            if(cell.getCellType() == CellType.NUMERIC){
                                                short format = cell.getCellStyle().getDataFormat();
                                                SimpleDateFormat sdf = null;
                                                if(format == 14 || format == 31 || format == 57 || format == 58){
                                                    //日期
                                                    sdf = new SimpleDateFormat("yyyy-MM-dd");
                                                }else if (format == 20 || format == 32) {
                                                    //时间
                                                    sdf = new SimpleDateFormat("HH:mm");
                                                }
                                                double v = cell.getNumericCellValue();
                                                Date dates = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(v);
                                                result1 = sdf.format(dates);
                                                enCaterParameter.setCleanRecord(result1);
                                                break;
                                            }
                                            enCaterParameter.setCleanRecord(cell.getStringCellValue());
                                            break;
                                        case 19:
                                            //是否使用碳
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setUseCarbon("1");
                                            }else {
                                                enCaterParameter.setUseCarbon("0");
                                            }
                                            break;
                                        case 20:
                                            //油烟在线监测
                                            if ("有".equals(cell.getStringCellValue().trim())){
                                                enCaterParameter.setMonitorOnline("1");
                                            }else {
                                                enCaterParameter.setMonitorOnline("0");
                                            }
                                            break;
                                        case 21:
                                            //备注
                                            enCaterParameter.setNote(cell.getStringCellValue());
                                            break;
                                        case 22:
                                            //位置坐标
                                        enCaterParameter.setS1(mapOwnerinfoMapper.selectCoordingbyName(cell.getStringCellValue()));
                                        break;
                                        default:
                                            json.setFlag(0);
                                            json.setMsg("err");
                                            break;
                                    }
                                }

                            }
                            enCaterParameter.setCreateUser(users.getUserId());
                            enCaterParameter.setCreateTime(DateFormat.getCurrentTime());
                            //将数据放入数据库
                            int count=enCaterParameterMapper.insertSelective(enCaterParameter);
                            if(count>0) {
                                successCount = successCount + count;
                            }
                            dest.delete();
                        }
                    }

                }
            }
            if(successCount>0){
                json.setTotleNum(successCount);
                json.setMsg("ok");
                json.setFlag(0);
                return  json;
            }
        }catch (Exception e){
            e.printStackTrace();
            json.setTotleNum(successCount+1);
            json.setFlag(1);
            json.setMsg(e.getMessage());
        }
        return json;

    }
    }
